package healthwatcher.aspects.storage;

import healthwatcher.Constants;

import java.io.File;

import org.jboss.aop.joinpoint.MethodInvocation;

import com.amazonaws.services.s3.model.CannedAccessControlList;
import com.amazonaws.services.s3.model.PutObjectRequest;

public class AspectStorageAWS {
	public Object store(MethodInvocation invocation) throws Throwable{
		
		String code=(String)invocation.getArguments()[0];
		File photo=(File)invocation.getArguments()[1];
		
		PutObjectRequest putRequest=new PutObjectRequest(Constants.S3BUCKET, 
				code+".jpg", photo);
		
		putRequest.setCannedAcl(CannedAccessControlList.PublicRead);
		
		System.out.println("Storage02AWS:"+System.nanoTime());
		
		Constants.getS3().putObject(putRequest);
		
			return invocation.invokeNext();
		
	}
}
